package com.json.model;

import com.alibaba.fastjson.JSON;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;

/**
 * json-manager
 * com.json.model
 * Description :
 * Name : zhang he
 * Date : 2022/12/16 下午6:26
 **/
public class TestUser {

    private EntityManager entityManager;

    @Before
    public void createEntityManager() throws IOException {
        entityManager = JSON.parseObject(loadJsonFileContext(), EntityManager.class);
    }

    public String  loadJsonFileContext() throws IOException {
        StringBuilder userJsonStr = new StringBuilder();
        InputStream userJson = TestUser.class.getClassLoader().getResourceAsStream("userJson");
        byte[] cache = new byte[1024];
        while (userJson.read(cache)!=-1){
            userJsonStr.append(new String(cache));
        }
        return userJsonStr.toString();
    }

    @Test
    public void updateUserId()  {
        User entityUser = entityManager.getEntityUser();
        Integer origId = entityUser.getId();
        System.out.println("原ID:"+origId);
        Integer newId = 100000;
        //设置成新ID
        entityUser.setId(newId);
        System.out.println("修改后的内容："+entityUser);
    }

}
